package com.msr.servlet;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.msr.analysis.Analysis;
import com.msr.bean.ConditionBean;
import com.msr.bean.Navi;
import com.msr.common.SysComm;
import com.msr.common.SysConstant;

/**
 * Servlet implementation class NaviServlet
 */
@WebServlet("/NaviServlet")
public class NaviServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public NaviServlet() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		// String act = request.getParameter(SysConstant.ACTION);
		String year = (request.getParameter("year") == null
				|| request.getParameter("year") == "" ? "" : (String) request
				.getParameter("year"));

		String month = (request.getParameter("month") == null
				|| request.getParameter("month") == "" ? "" : (String) request
				.getParameter("month"));

		String area = (request.getParameter("area") == null
				|| request.getParameter("area") == "" ? "" : (String) request
				.getParameter("area"));

		String region = (request.getParameter("region") == null
				|| request.getParameter("region") == "" ? "" : (String) request
				.getParameter("region"));

		String account = (request.getParameter("account") == null
				|| request.getParameter("account") == "" ? ""
				: (String) request.getParameter("account"));

		String channel = (request.getParameter("channel") == null
				|| request.getParameter("channel") == "" ? ""
				: (String) request.getParameter("channel"));
		ConditionBean condition = new ConditionBean();
		condition.setAccount(account);
		condition.setArea(area);
		condition.setChannel(channel);
		condition.setRegion(region);
		try{
			condition.setYearmonth(Integer.parseInt(year+month));
		}
		catch(Exception e)
		{
			condition.setYearmonth(SysComm.getMaxYM());
		}
		
		
		Analysis analysis = new Analysis();
		Navi bean = analysis.navi();
		request.setAttribute(SysConstant.PARAM, bean);
		RequestDispatcher dispatcher = getServletContext()
				.getRequestDispatcher("/WEB-INF/jsp/analysis/navi.jsp");
		dispatcher.forward(request, response);

	}

}
